package com.example.jvm.chapter02;

import java.util.PriorityQueue;

/**
 * @Date 2024-01-11
 * @Author Jonathan
 */
public class PriorityQueueDemo {
    public static void main(String[] args) {

        PriorityQueue<Student> students = new PriorityQueue<>(10, (student1, student2) -> student2.getScore() - student1.getScore());
        students.add(new Student(10, "张三"));
        students.add(new Student(11, "李四"));
        Student student = students.poll();
        System.out.println(student);
    }


    static class Student {
        private Integer score;
        private String name;

        public Student(Integer score, String name) {
            this.score = score;
            this.name = name;
        }

        public Integer getScore() {
            return score;
        }

        public void setScore(Integer score) {
            this.score = score;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        @Override
        public String toString() {
            return "Student{" +
                    "score=" + score +
                    ", name='" + name + '\'' +
                    '}';
        }
    }
}
